/*
 * Copyright 2025 arisgo@163.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.arisgo.cloud.flux.mybatis.search;

import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.util.CollectionUtil;

import java.util.List;

/**
 * @author Coulson
 * @since 2023-8-22
 */
public class SearchParam {

    private Selected selected;

    private List<Param> params;

    private List<Sort> sorts;

    public QueryWrapper buildWrapper() {
        QueryWrapper wrapper = new QueryWrapper();
        buildWrapper(wrapper);
        return wrapper;
    }

    public void buildWrapper(QueryWrapper wrapper) {
        if (null == wrapper) {
            return;
        }

        if (CollectionUtil.isNotEmpty(this.params)) {
            for (Param param : params) {
                param.buildWrapper(wrapper);
            }
        }

        if (null != this.selected) {
            this.selected.buildWrapper(wrapper);
        }

        if (CollectionUtil.isNotEmpty(this.sorts)) {
            for (Sort sort : sorts) {
                sort.buildWrapper(wrapper);
            }
        }
    }

    public List<Param> getParams() {
        return params;
    }

    public void setParams(List<Param> params) {
        this.params = params;
    }

    public Selected getSelected() {
        return selected;
    }

    public void setSelected(Selected selected) {
        this.selected = selected;
    }

    public List<Sort> getSorts() {
        return sorts;
    }

    public void setSorts(List<Sort> sorts) {
        this.sorts = sorts;
    }

}
